//用户角色相关接口
import request from "@/utils/request.ts";
import type {} from "./type";

enum API {
  // DELETE
  batchRemove = "/admin/acl/role/batchRemove",
  // 根据id列表删除角色

  // GET
  get = "/admin/acl/role/get",
  // 获取角色

  // DELETE
  remove = "/admin/acl/role/remove",
  // 删除角色

  // POST
  save = "/admin/acl/role/save",
  // 新增角色

  // PUT
  update = "/admin/acl/role/update",
  // 修改角色

  // GET
  role = "/admin/acl/role",
  // 获取角色分页列表

  // GET
  toAssign = "/admin/acl/permission/toAssign",
  // 根据角色ID获取权限菜单

  // POST
  doAssign = "/admin/acl/permission/doAssign",
  // 给角色分配权限
}

export const batchRemove = (dataArr: any) => {
  let data: any = { data: dataArr };
  return request.delete<any, any>(API.batchRemove, data);
};

export const get = (id: any) => {
  return request.get<any, any>(API.get + `/${id}`);
};

export const remove = (id: any) => {
  return request.delete<any, any>(API.remove + `/${id}`);
};

export const save = (data: any) => {
  return request.post<any, any>(API.save, data);
};

export const update = (data: any) => {
  return request.put<any, any>(API.update, data);
};

export const role = (pageNo: number, limit: number, roleName: string) => {
  if (roleName.length <= 0) {
    return request.get<any, any>(API.role + `/${pageNo}/${limit}`);
  } else {
    return request.get<any, any>(
      API.role + `/${pageNo}/${limit}?roleName=${roleName}`,
    );
  }
};

export const toAssign = (roleId: any) => {
  return request.get<any, any>(API.toAssign + `/${roleId}`);
};

export const doAssign = (permissionId: number[], roleId: number) => {
  return request.post<any, any>(
    API.doAssign + `?permissionId=${permissionId}&roleId=${roleId}`,
  );
};
